<?php
/**
 * Created by lzl.
 * Date: 2021 2021/10/3 0003
 * Time: 10:41
 */
namespace App\Http\Controllers\Admin;

use App\Exceptions\RequestException;
use App\Forms\GoodsAttributeForms;

class SkuController extends Controller
{

    /**
     * sku列表
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
     * @throws RequestException
     */
    public function skuList()
    {
        $form = new GoodsAttributeForms();

        if($this->request->ajax()) {
            $rules = [
                'page'  => 'required',
                'limit' => 'required',
            ];

            $this->validateInput($rules);

            return $this->showJsonLayui($form->getSkuList($this->validated));

        }
        return $this->view('sku.list');
    }


    /**
     * 编辑sku
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
     * @throws RequestException
     */
    public function edit()
    {
        $rules = [
            'id'        => 'nullable',
            'sku_name'  => 'nullable',
            'sku_value' => 'nullable'
        ];

        $this->validateInput($rules);

        $form = new GoodsAttributeForms();

        if($this->request->isMethod('post')) {
            return $this->success($form->editSku($this->validated));
        }

        return $this->view('sku.edit', ['model' => $form->getSkuDetail($this->validated)]);

    }


    /**
     * 删除sku
     * @return mixed
     * @throws RequestException
     */
    public function delete()
    {
        $rules = [
            'id' => 'nullable',
        ];

        $this->validateInput($rules);

        return $this->success(( new GoodsAttributeForms())->delete($this->validated));
    }


    /**
     * sku 详情接口
     * @return mixed
     * @throws RequestException
     */
    public function detail()
    {
        $rules = [
            'id' => 'required',
        ];

        $this->validateInput($rules);

        return $this->success(( new GoodsAttributeForms())->getSkuDetail($this->validated));
    }
}